<?php
namespace app\common\model;
use app\common\model\account\ShopAccountModel;
use app\common\model\CommonModel;
use app\common\model\AppModel;
class ShopModel extends CommonModel{
    protected  $name = 'shop';
    protected  $pk   = 'shop_id';
    protected $type_mean=[
        -1=>'取消授权',
        0=>'等待授权',
        1=>'已经授权',
        8=>'已经上线运营'
    ];

    public function application()
    {
        return $this->hasOne(AppModel::class,'app_id','app_id');
    }

    public function relation()
    {
        return $this->hasOne(ShopAccountModel::class,'shop_id','shop_id');
    }

    public function app()
    {
        return $this->hasOne(AppModel::class,'app_id','app_id');
    }

    public function kefu()
    {
        return $this->hasOne(CustomerServiceModel::class,'customer_service_id','customer_service_id');
    }

    public function getStatusMeanAttr($value,$data)
    {
        return $this->type_mean[$data['status']] ?? '状态异常';
    }

    public function getExpireTimeFormatAttr($value,$data)
    {
        return date("Y-m-d",$data['expire_time']);
    }

    public function getIsExpireAttr($value,$data)
    {
        return $data['expire_time'] >= time() ? 0 : 1;
    }
}
